package com.majsubtense.core.achievements;

import com.majsubtense.core.components.UI;
import com.majsubtense.core.events.EventHandler;
import com.majsubtense.core.events.GameSceneChangeEvent;

public class PressSettingButtonAchievement extends CountTriggeredAchievement {
    public static final AchievementType<PressSettingButtonAchievement> ANY;

    public PressSettingButtonAchievement() {
        super(PressSettingButtonAchievement.ANY, "你铁暗恋我的设置按钮！");

        setTriggeredMessages(new String[]{
                "你想设置啥啊，有啥好设置的，有什么不满吗？",
                "嗯？真的没有做有关设置的东西，相信我！",
                "我该鼓励你的执着，但是你应该把它用在其他地方。",
                "我想你是不是应该尝试一下进入游戏？",
                "试完了就可以退出了，这个功能就是用来测试的",
                "......",
                "您好，您当前网络断开连接...",
                "咳咳，我忘记这是个单机游戏了",
                "不过问题不大，你该换一件事去做了",
                "再见"
        });

        setCountGenerator(() -> Math.min(count + 1, getTriggeredMessages().length) - 1);

        UI.addListener(new EventHandler<>(
                GameSceneChangeEvent.ANY,
                gameSceneChangeEvent -> {
                    if (gameSceneChangeEvent.getChangeTo().equals("Settings")) {
                        count = Math.min(count + 1, getTriggeredMessages().length);
                    }
                    if (count == getTriggeredMessages().length)
                        finishAchievement();
                }
        ));
    }

    @Override
    public void finishAchievement() {
        if (!isFinished()) {
            AchievementController.showAchievementDialog(this);
            setFinished(true);
        }
    }

    static {
        ANY = new AchievementType<>(CountTriggeredAchievement.ANY, "PRESS_SETTING_BUTTON");
    }
}
